import java.io.File;
import java.io.FileInputStream;
import java.io.FilenameFilter;

public class TextDemo {
    public static void deleteDir(File file){
        if(file.exists()){
            File[] files = file.listFiles();
            for(int i = 0;i<files.length;i++){
                if(files[i].isDirectory()){
                    deleteDir(files[i]);
                }else{
                    files[i].delete();
                }
            }
            file.delete();

        }
    }

    public static void main(String[] args) {
        File file = new File("D:/日常任务");
        deleteDir(file);
        System.out.println("删除成功");
    }


    public static void fileDir(File file){
        File[] files = file.listFiles();
        for(int i = 0;i< files.length;i++){
            if(files[i].isDirectory()){
                fileDir(files[i]);
            }
            System.out.println(files[i].getAbsoluteFile());
        }
    }
    public static void main3(String[] args) {
        File file = new File("D:/Users");
        fileDir(file);
    }
    public static void main2(String[] args) {
        File file = new File("D:/Users");
        FilenameFilter filter = new FilenameFilter() {
            @Override
            public boolean accept(File dir, String name) {
                File currFile = new File(dir,name);
                if(currFile.isFile()&&name.endsWith(".java")){
                    return true;
                }else{
                    return false;
                }

            }
        };
        if(file.exists()){
            String[] list = file.list(filter);
            for(int i = 0;i< list.length;i++){
                System.out.println(list[i]);
            }
        }
    }
    public static void main1(String[] args) {
        File file = new File("D:/Users");
        if(file.isDirectory()){
            String[] name = file.list();
            for(int i = 0;i<name.length;i++){
                System.out.println(name[i]);
            }
            return ;
        }else{
            System.out.println("不是目录");
            return ;
        }
    }

}
